using UnityEngine;
using System.Collections;


public class GuiKeyboardHandler : MonoBehaviour {

    // ----- internal methods -------------------------------------------------
    void OnGUI() {
        if (Event.current.Equals(Event.KeyboardEvent("ESCAPE"))) {
            print("Quitting");
            Application.Quit();
        }

        if (Event.current.Equals(Event.KeyboardEvent("F12"))) {
            string filename = GetScreenshotFilename();
            print("Screenshot written to " + filename);
            Application.CaptureScreenshot(filename);
        }
    }


    // ----- private methods --------------------------------------------------
    private string GetScreenshotFilename() {
        System.IO.Directory.CreateDirectory ("Screenshots");
        int i = 1;
        while (System.IO.File.Exists (System.IO.Path.Combine ("Screenshots", "screenshot" + i + ".png"))) {
            i++;
        }
        return System.IO.Path.Combine ("Screenshots", "screenshot" + i + ".png");
    }
}
